<template>
  <div class="app-container">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="调整入库" name="first"></el-tab-pane>
      <el-tab-pane label="调整出库" name="second"></el-tab-pane>
    </el-tabs>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
      <el-form-item label="物料名称" prop="num">
        <el-input
          v-model="queryParams.num"
          placeholder="请输入"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="调入仓库" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in options"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="调出仓库" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in options"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="入库单号" prop="num">
        <el-input
          v-model="queryParams.num"
          placeholder="请输入"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出库单号" prop="num">
        <el-input
          v-model="queryParams.num"
          placeholder="请输入"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="入库时间">
        <el-date-picker
          v-model="queryParams.value1"
          type="date"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="出库时间" prop="roleName">
        <el-input
          v-model="queryParams.roleName"
          placeholder="请输入"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button @click="handleAdd" size="mini">新增</el-button>
        <el-button @click="handleEdit" size="mini">编辑</el-button>
        <el-button @click="handleDelete" size="mini">删除</el-button>
      </el-col>
    </el-row>
    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="物料名称" prop="roleName" />
      <el-table-column label="调入仓库" prop="roleKey"  />
      <el-table-column label="入库单号" prop="roleSort" />
      <el-table-column label="入库时间" prop="roleSort" width="100" />
      <el-table-column label="调出仓库" prop="roleSort" width="100" />
      <el-table-column label="出库单号" prop="roleSort" />
      <el-table-column label="出库时间" prop="roleSort" />
      <el-table-column label="调整数量" prop="roleSort" width="100" />
      <el-table-column label="调整单位" prop="roleSort" width="100" />
      <el-table-column label="调整前库存" prop="roleSort" />
      <el-table-column label="调整后库存" prop="roleSort" />
      <el-table-column label="备注" prop="roleSort" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 新增编辑弹窗 -->
    <el-dialog  class="scrollbar" :title="title" :visible.sync="open" width="550px" append-to-body>
      <el-form ref="form" :rules="rules" :model="form" label-width="110px">
        <el-form-item label="物料名称" prop="q">
          <el-input v-model="form.q" :readonly="isReadOnly" />
        </el-form-item>
        <el-form-item label="调入仓库" prop="w">
          <el-select style="width: 100%;" v-model="form.w" :readonly="isReadOnly" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="入库单号" prop="e">
          <el-input v-model="form.e" :readonly="isReadOnly" />
        </el-form-item>
        <el-form-item label="入库时间" prop="r">
          <el-date-picker
            v-model="form.r"
            type="date"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="调出仓库" prop="r">
          <el-select style="width: 100%;" v-model="form.w" :readonly="isReadOnly" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="出库单号" prop="r">
          <el-input v-model="form.r" :readonly="isReadOnly" />
        </el-form-item>
        <el-form-item label="出库时间" prop="r">
          <el-date-picker
            v-model="form.r"
            type="date"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="调整数量" prop="r">
          <el-input v-model="form.r" :readonly="isReadOnly" />
        </el-form-item>
        <el-form-item label="调整单位" prop="r">
          <el-input v-model="form.r" :readonly="isReadOnly" />
        </el-form-item>
        <el-form-item label="调整前库存" prop="r">
          <el-input v-model="form.r" :readonly="isReadOnly" />
        </el-form-item>
        <el-form-item label="调整后库存" prop="r">
          <el-input v-model="form.r" :readonly="isReadOnly" />
        </el-form-item>
        <el-form-item label="备注" prop="r">
          <el-input v-model="form.r" :readonly="isReadOnly" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-if="title !== '查看'" type="primary" @click="submit">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRole } from "@/api/system/role";

export default {
  data() {
    return {
      // 是否只读
      isReadOnly: false,
      // tab
      activeName: 'first',
      // 下拉数据
      options: [],
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roleName: undefined,
        status: undefined,
        num: undefined
      },
      // 表单
      open: false,
      title: '新增',
      rules: {
        q: [{ required: true, message: '请输入', trigger: 'blur' }],
        w: [{ required: true, message: '请选择', trigger: 'change' }],
        e: [{ required: true, message: '请输入', trigger: 'blur' }],
        r: [{ required: true, message: '请输入', trigger: 'blur' }],
      },
      form: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 切换tab页
    handleClick(tab, event) {
      this.queryParams.pageNum = 1
    },
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      listRole(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.list = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 重置
    reset() {
      this.form = {
        q: '',
        w: '',
        e: '',
        r: ''
      }
      this.isReadOnly = false
    },
    // 新增
    handleAdd() {
      this.reset()
      this.title = '新增'
      this.open = true
    },
    // 查看
    handleView() {
      this.reset()
      this.title = '查看'
      this.isReadOnly = true
      this.open = true
    },
    // 编辑
    handleEdit() {
      this.reset()
      this.title = '编辑'
      this.open = true
    },
    // 删除
    handleDelete() {
      this.$modal
        .confirm("确定要删除该记录吗？")
        .then(() => {
          
        })
    },
    // 表单确定
    submit() {

    },
    // 表单取消
    cancel() {
      this.open = false
    }
  }
};
</script>
